<template>
    <div class="register-container">
      <el-card class="register-box">
        <h2 class="register-title">用户注册</h2>
        <el-form :model="form" label-width="80px">
          <el-form-item label="用户名">
            <el-input v-model="form.username" />
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.password" type="password" />
          </el-form-item>
          <el-form-item label="确认密码">
            <el-input v-model="form.confirmPassword" type="password" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleRegister">注册</el-button>
            <el-button @click="$router.push('/login')">返回登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  import { ElMessage } from 'element-plus'
  
  const router = useRouter()
  
  const form = ref({
    username: '',
    password: '',
    confirmPassword: ''
  })
  
  const handleRegister = async () => {
    if (form.value.password !== form.value.confirmPassword) {
      ElMessage.error('两次输入的密码不一致')
      return
    }
    
    // 模拟注册逻辑
    try {
      // 调用注册API
      await new Promise(resolve => setTimeout(resolve, 500))
      ElMessage.success('注册成功')
      router.push('/login')
    } catch (error) {
      ElMessage.error('注册失败')
    }
  }
  </script>
  
  <style scoped>
  .register-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8f8f9;
  }
  
  .register-box {
    width: 500px;
    padding: 30px;
  }
  
  .register-title {
    text-align: center;
    margin-bottom: 30px;
    color: #303133;
  }
  </style>